package cn.kgc.service.impl;

import cn.kgc.dao.NewsCategoryDao;
import cn.kgc.dao.NewsDao;
import cn.kgc.dao.impl.NewsCategoryDaoImpl;
import cn.kgc.dao.impl.NewsDaoImpl;
import cn.kgc.pojo.News;
import cn.kgc.pojo.NewsCategory;
import cn.kgc.service.NewsService;

import java.util.List;

/**
 * Created by Administrator on 2018/12/28.
 */
public class NewsServiceImpl implements NewsService{
    private NewsDao newsDao;
    private NewsCategoryDao newsCategoryDao;

    public NewsServiceImpl(){
        newsDao = new NewsDaoImpl();
        newsCategoryDao = new NewsCategoryDaoImpl();
    }

    public void getNewsListByDS() {
        newsDao.getNewsListByDS();
    }

    public boolean addNews(News news) {
        return newsDao.addNews(news);
    }

    public boolean deleteNews(News news) {
        return newsDao.deleteNews(news);
    }

    public boolean updateNews(News news) {
        return newsDao.updateNews(news);
    }

    public boolean updateNewsTitle(News news) {
        return newsDao.updateNewsTitle(news);
    }

    public List<News> getNewsList() {
        return newsDao.getNewsList();
    }

    public void getNewsByTitle(News news) {
        newsDao.getNewsByTitle(news);
    }

    public int getCountByCategory(NewsCategory newsCategory) {
        return newsDao.getCountByCategory(newsCategory);
    }

    public News getNewsListById(int id) {
        return newsDao.getNewsListById(id);
    }

    public int getTotalCount() {
        return newsDao.getTotalCount();
    }

    public List<News> getPageNewsList(int pageNo, int pageSize) {
        return newsDao.getPageNewsList(pageNo,pageSize);
    }


    /**
     * main方法，用于测试
     * @param args
     */
    public static void main(String[] args) {
        NewsService newsService = new NewsServiceImpl();
        List<News> list = newsService.getNewsList();
        for (News news : list) {
            System.out.print(news.getId()+"\t");
            System.out.println(news.getTitle());
        }
    }
}
